package no.hig.imt4721.matching;

import java.util.ArrayList;
import java.util.List;

import no.hig.imt4721.model.Repetition;
import no.hig.imt4721.model.Session;
import no.hig.imt4721.model.Subject;
import no.hig.imt4721.model.Template;

public class Matcher
{
	public DistanceMetric metric = null;
	
	List<Double> genuineScores = new ArrayList<Double>();
	List<Double> impostorScores = new ArrayList<Double>();
	
	List<Subject> inputs;
	List<Template> templates;
	
	public Matcher(DistanceMetric metric, List<Subject> inputs, List<Template> templates)
	{
		this.metric = metric;
		this.inputs = inputs;
		this.templates = templates;
		
		//System.out.println("Calculating scores started.");
		calculateScores();
		//System.out.println("Calculating scores stopped.");
	}
	
	public double getGEN()
	{
		return genuineScores.size();
	}
	
	public double getIMP()
	{		
		return impostorScores.size();
	}
	
	public List<Double> getGenuineScores()
	{
		return genuineScores;
	}
	
	public List<Double> getImpostorScores()
	{
		return impostorScores;
	}
	
	private void calculateScores()
	{		
		for(int subjectNumber = 0; subjectNumber < inputs.size(); subjectNumber++)
		{
			Subject subject = inputs.get(subjectNumber);
			
			for(Session session : subject.getSessions())
			{
				for(Repetition repetition : session.getRepetitions())
				{
					for(int templateNumber = 0; templateNumber < templates.size(); templateNumber++)
					{
						Template template = templates.get(templateNumber);
						
						double d = metric.getDistance(template, repetition);
						
						if(templateNumber == subjectNumber) // Genuine score
							genuineScores.add(d);
						else // Impostor score
							impostorScores.add(d);
					}
				}
			}
		}
	}	
}
